package com.hexacta.hrs.web.struts.actions.staffing;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.vectrics.common.util.DateUtil;
import org.vectrics.employee.Employee;
import org.vectrics.location.Location;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.JobFunction;
import org.vectrics.recruiter.struts.tag.AvailabilityStatusColor;
import org.vectrics.user.Person;

import com.hexacta.hrs.domain.helper.EmployeeAssignmentHelper;
import com.hexacta.hrs.domain.staffing.Project;
import com.hexacta.hrs.domain.staffing.Requirement;
import com.hexacta.hrs.domain.staffing.assignment.AssignmentType;
import com.hexacta.hrs.domain.staffing.assignment.AvailabilityStatus;
import com.hexacta.hrs.domain.staffing.assignment.EmployeeAssignment;
import com.hexacta.hrs.service.staffing.ProjectService;
import com.hexacta.hrs.services.crud.CrudService;
import com.hexacta.hrs.services.employee.EmployeeService;
import com.hexacta.hrs.services.feedbacks.FeedbackPeriodService;
import com.hexacta.hrs.services.feedbacks.FeedbackService;
import com.hexacta.hrs.services.staffing.EmployeeAssignmentService;
import com.hexacta.hrs.services.staffing.impl.EmployeeAssignmentDTO;
import com.hexacta.hrs.web.struts.actions.CrudAbstractAction;

import edu.emory.mathcs.backport.java.util.Collections;

public class EmployeeAssignmentAction extends CrudAbstractAction<EmployeeAssignment> implements SessionAware {

    private static final long serialVersionUID = 993786899395795283L;

    private static final String LIST = "listAssignments";

    private static final String CREATE_NEW = "createNewAssignment";

    private static final String EDIT = "editAssignment";

    private static final String CONFIRM_NEW = "confirmNewAssignment";

    private static final String DELETE = "deleteAssignment";

    public static final String SUCCESS = "success";

    public static final String FROM_POPUP = "fromPopUp";

    private Map session;

    private Boolean validated = Boolean.FALSE;

    private String employeeId;

    private String projectId;

    private String roleId;

    private String selectedGanttEmployeeId;

    private String selectedGanttEmployeeIdBefore;

    private String selectedGanttEmployeeNameBefore;

    private long assignmentId;

    private String assignmentIdBefore;

    private EmployeeAssignment assignment;

    private EmployeeAssignmentService employeeAssignmentService;

    private EmployeeService employeeService;

    private FeedbackPeriodService feedbackPeriodService;

    private FeedbackService feedbackService;

    private List<EmployeeAssignmentDTO> employeeAssignmentList;

    private List<EmployeeAssignment> assignmentList;
    
    private List<Location> locationList;

    private String selectedProjectId;

    private String selectedProjectName;

    private ProjectService projectService;

    private String selectedRoleCode;

    private String selectedRoleName;

    private Date selectedStartDate;

    private Date selectedEndDate;
    
    private String selectedLocationId;
    
    private String selectedLocationName;
    
    private Date defaultStartDate;

    private Date defaultEndDate;

    private String description = "";

    private String selectedAssignmentPercentage = "100";

    private boolean addonAvailable = false;

    private boolean addonNotAvailable = false;

    private boolean assignTentative = false;

    private boolean createRequirement = true;

    private String assignmentToDelete;

    private String resetAttributes = "";

    private boolean fromPopUp = false;

    // Atributos para el gantt de recursos.
    private String actualPage = "1";

    private boolean showNoAsignado = false;

    private boolean showAsignadoCliente = true;

    private boolean showAddOnAvailable = true;

    private boolean showAddOnNotAvailable = true;

    private boolean showInterno = true;

    private boolean showTodos = false;

    private boolean showTentativesAvailableResources = true;

    private boolean showTimeOff = false;

    private boolean onlyElegibleProjectMember = true;

    private String[] selectedRoles = new String[] {};

    private String selectedEmployeeId = "";

    private String selectedEmployeeName = "";

    private Date ganttStartDate;

    private Date ganttEndDate;

    private Collection<String> selectedRolesBefore = new ArrayList<String>();

    private String selectedProjectIdFilter;

    private String selectedProjectNameFilter;

    private EditedAssignment editedAssignment;

    private Long selectedAssignmentId;

    /**
     * Lista todas las asignaciones.
     */
    @SkipValidation
    public final String listAssignments() {
        if (StringUtils.equalsIgnoreCase(getResetAttributes(), "true")) {
            resetAttributesForm();
        }

        loadDates();

        Employee employee;
        if (StringUtils.isEmpty(getSelectedEmployeeId()) || StringUtils.isEmpty(getSelectedEmployeeName())) {
            employee = null;
        } else {
            employee = getEmployeeService().searchById(Long.parseLong(getSelectedEmployeeId()));
        }
        validateAutocompleter();
        
        Location selectedLocation = null;
        if(getSelectedLocationId()!=null){
        	selectedLocation = CoreServiceLocator.getLocationService().findLocation(Long.parseLong(getSelectedLocationId()));
        }
        
        setEmployeeAssignmentList(getEmployeeAssignmentService().findAvailableResource(employee,
                getSelectedStartDate(), getSelectedEndDate(), getShowTentativesAvailableResources(),
                getShowNoAsignado(), getShowAsignadoCliente(), isShowAddOnAvailable(), isShowAddOnNotAvailable(),
                getShowInterno(), getShowTimeOff(), getSelectedRoles(), getSelectedProjectIdFilter(),
                isOnlyElegibleProjectMember(), selectedLocation));

        // Cargamos las fechas del intervalo que va a mostrar el Gantt.
        setGanttStartDate(getSelectedStartDate());
        setGanttEndDate(getSelectedEndDate());

        // Cargamos en la lista selectedRolesBoefore, las keys de los roles
        // anteriormente selecionados, para que cuando se cargue de nuevo la
        // pagina no se pierdan
        loadSelectedRolesBefore();

        saveSearchCriteria();

        setMappedRequest(LIST);
        return SUCCESS;
    }

    private void validateAutocompleter() {
        if (selectedProjectNameFilter == null || selectedProjectNameFilter.trim().equalsIgnoreCase("")) {
            selectedProjectIdFilter = null;
        }
        if (selectedEmployeeName == null || selectedEmployeeName.trim().equalsIgnoreCase("")) {
            selectedEmployeeId = null;
        }

    }

    private void loadSelectedRolesBefore() {
        if (selectedRoles != null) {
            CollectionUtils.addAll(getSelectedRolesBefore(), selectedRoles);
        }
    }

    /**
     * Prepara la pantalla para crear una nueva asignacion para el empleado.
     * 
     * @return
     */
    @SkipValidation
    public final String createNewAssignment() {

        resetAttributesForCreateNewAssignments();

        Employee employee = null;
        if (StringUtils.isNotEmpty(getEmployeeId())) {
            employee = getEmployeeService().searchById(Long.decode(getEmployeeId()));
            this.loadEmployeeAssignmentsList(employee);
            loadAttributesWithNextNoAssignment(employee);

            if (StringUtils.isEmpty(getSelectedRoleCode())) {
                setSelectedRoleCode(employee.getFunction().getCode());
            }
            if (StringUtils.isEmpty(getSelectedRoleName())) {
                setSelectedRoleName(employee.getFunction().getDescription());
            }

        }

        if (isFromPopUp())
            return FROM_POPUP;
        return SUCCESS;
    }

    /**
     * Carga los valores iniciales de algunos atributos para cuando se quiere
     * crear una nueva asignacion.
     */
    private void resetAttributesForCreateNewAssignments() {
        setAssignmentId(0);
        setAssignmentIdBefore("");

        if (StringUtils.isEmpty(getEmployeeId())) {
            if (StringUtils.isNotEmpty(getSelectedGanttEmployeeId())) {
                setEmployeeId(getSelectedGanttEmployeeId());
            } else if (StringUtils.isNotEmpty(getSelectedGanttEmployeeIdBefore())) {
                setEmployeeId(getSelectedGanttEmployeeIdBefore());
            }
        }
        setGanttStartDate(StaffingActionHelper.GenerarValorInicialDeStartDate());
        setGanttEndDate(StaffingActionHelper.GenerarValorInicialDeEndDate());

        setAddonAvailable(false);
        setAddonNotAvailable(false);
        setAssignTentative(false);
        setDescription("");
        if (StringUtils.isBlank(getSelectedGanttEmployeeIdBefore())
                && !StringUtils.isBlank(getSelectedGanttEmployeeId())) {
            setSelectedGanttEmployeeIdBefore(getSelectedGanttEmployeeId());
            setSelectedGanttEmployeeNameBefore(getEmployeeService()
                    .searchById(Long.parseLong(getSelectedGanttEmployeeIdBefore())).getPerson().getName());
        }
        setMappedRequest(CREATE_NEW);
    }

    private void loadDates() {
        if (getSelectedStartDate() == null) {
            Date selectedStartDate = StaffingActionHelper.GenerarValorInicialDeStartDate();
            setSelectedStartDate(selectedStartDate);
        }

        if (getSelectedEndDate() == null) {
            Date selectedEndDate = StaffingActionHelper.GenerarValorInicialDeEndDate();
            setSelectedEndDate(selectedEndDate);
        }
    }

    /**
     * Confirma la creacion de la nueva asignacion con los datos ingresados.
     * 
     * @return
     */
    public final String confirmNewAssignment() {

        if (getAssignmentIdBefore() == null || getAssignmentIdBefore().equals("")) {
            // Esto significa que ningun assignment fue seleccionado
            // para ser editado, por lo que debe crearse un nuevo nuevo
            // Assignment
            Employee employee = getEmployeeService().searchById(Long.decode(getEmployeeId()));
            this.loadEmployeeAssignmentsList(employee);
            // loadDates();

            EmployeeAssignment newAssignment = new EmployeeAssignment();
            newAssignment.setAssignmentPorcentage(Long.parseLong(getSelectedAssignmentPercentage()));
            newAssignment.setComments(description);
            newAssignment.setEmployee(employee);

            JobFunction role = new JobFunction();

            role = RecruitServiceLocator.getJobProvider().findFunction(getSelectedRoleCode());

            newAssignment.setAssignedRole(role);

            Calendar endDate = Calendar.getInstance();
            if (getSelectedEndDate() != null) {
                endDate.setTime(getSelectedEndDate());
            } else if (getDefaultEndDate() != null) {
                endDate.setTime(getDefaultEndDate());
            }
            newAssignment.setEndDate(endDate);

            Calendar startDate = Calendar.getInstance();
            if (getSelectedStartDate() != null) {
                startDate.setTime(getSelectedStartDate());
            } else if (getDefaultStartDate() != null) {
                startDate.setTime(getDefaultStartDate());
            }
            newAssignment.setStartDate(startDate);

            if (isAddonAvailable()) {
                newAssignment.setAssignmentType(AssignmentType.AddOnAvailable);
            } else if (isAddonNotAvailable()) {
                newAssignment.setAssignmentType(AssignmentType.AddOnNotAvailable);
            } else {
                newAssignment.setAssignmentType(AssignmentType.Assigned);
            }

            newAssignment.setTentative(isAssignTentative());

            Project project = getProjectService().searchById(Long.parseLong(getSelectedProjectId()));

            if (createRequirement) {
                Requirement req = new Requirement();
                req.setAssignmentPorcentage(Long.parseLong(getSelectedAssignmentPercentage()));
                req.setEndDate(endDate);
                req.setRequiredRol(role);
                req.setStartDate(startDate);

                project.addRequirement(req);
            }

            if (!validateNoDuplicateAssigment(newAssignment, project)) {
                project.addAssignment(newAssignment);
                getProjectService().save(project);
                feedbackService.addFeedbackFromAssignment(newAssignment);

            } else {
                newAssignment.setProject(null);
                project.removeAssignment(newAssignment);
                getProjectService().save(project);
                addActionError("The employee is already assigned to this project.");
            }

        } else {
            // esto quiere decir que debemos modificar el assignment
            // seleccionado
            Project project = getProjectService().searchById(Long.parseLong(getSelectedProjectId()));

            EmployeeAssignment assignment;

            if (getAssignmentIdBefore() != null) {
                assignment = getEmployeeAssignmentService().searchById(Long.parseLong(getAssignmentIdBefore()));
            } else {
                assignment = getEmployeeAssignmentService().searchById(getSelectedAssignmentId());
            }
            assignment.setAssignedRole(RecruitServiceLocator.getJobProvider().findFunction(getSelectedRoleCode()));
            assignment.setAssignmentPorcentage(Long.parseLong(getSelectedAssignmentPercentage()));

            if (isAddonAvailable()) {
                assignment.setAssignmentType(AssignmentType.AddOnAvailable);
            } else if (isAddonNotAvailable()) {
                assignment.setAssignmentType(AssignmentType.AddOnNotAvailable);
            } else {
                assignment.setAssignmentType(AssignmentType.Assigned);
            }
            assignment.setComments(getDescription());
            assignment.setEndDate(DateUtil.toCalendar(getSelectedEndDate()));
            assignment.setStartDate(DateUtil.toCalendar(getSelectedStartDate()));
            assignment.setProject(project);
            assignment.setTentative(isAssignTentative());

            project.addAssignment(assignment);
            getProjectService().save(project);

            Person person = CoreServiceLocator.getUserAuthService().getAuthorizedPerson(getSession());
            feedbackService.updateFeedbacksForASsignment(assignment, person);
        }

        setGanttStartDate(StaffingActionHelper.GenerarValorInicialDeStartDate());

        setGanttEndDate(StaffingActionHelper.GenerarValorInicialDeEndDate());

        setSelectedGanttEmployeeId(getSelectedEmployeeId());

        setEmployeeId(getEmployeeId());

        setSelectedEmployeeId(getEmployeeId());

        setMappedRequest(CONFIRM_NEW);

        if (isFromPopUp())
            return FROM_POPUP;
        return SUCCESS;
    }

    /**
     * @return the feedbackPeriodService
     */
    public FeedbackPeriodService getFeedbackPeriodService() {
        return feedbackPeriodService;
    }

    /**
     * @param feedbackPeriodService
     *            the feedbackPeriodService to set
     */
    public void setFeedbackPeriodService(final FeedbackPeriodService feedbackPeriodService) {
        this.feedbackPeriodService = feedbackPeriodService;
    }

    /**
     * @return the feedbackService
     */
    public FeedbackService getFeedbackService() {
        return feedbackService;
    }

    /**
     * @param feedbackService
     *            the feedbackService to set
     */
    public void setFeedbackService(final FeedbackService feedbackService) {
        this.feedbackService = feedbackService;
    }

    /**
     * Valida que los datos ingresados para crear una nueva asignacion sean
     * validos.
     * 
     * @return
     */
    public String validateConfirmNewAssignment() {
        if (getValidated()) {// already validated and accepted the message
            setMappedRequest(CONFIRM_NEW);
            return SUCCESS;
        }

        Boolean error = Boolean.FALSE;

        // Valido que el proyecto indicado realmente exista.
        if (StringUtils.isEmpty(getSelectedProjectId()) || StringUtils.isEmpty(getSelectedProjectName())) {
            error = Boolean.TRUE;
            addFieldError("project", "Project is required.");
        }

        // Valido que el rol indicado sea valido.
        if (StringUtils.isEmpty(getSelectedRoleCode()) || StringUtils.isEmpty(getSelectedRoleName())) {
            error = Boolean.TRUE;
            addFieldError("role", "Assigned Role is required.");
        }

        // valido que el porcentaje sea menor o igual a 100 y mayor a cero.
        if (StringUtils.isNotEmpty(getSelectedAssignmentPercentage())) {
            Long percentage;
            try {
                percentage = Long.parseLong(getSelectedAssignmentPercentage());
                if (percentage <= 0 || percentage > 100) {
                    error = Boolean.TRUE;
                    addFieldError("percentage",
                            "Percentage must be a number greatear than zero and less or equal to 100.");
                }
            } catch (NumberFormatException e) {
                error = Boolean.TRUE;
                addFieldError("percentage", "Percentage must be a number.");
            }
        } else {
            error = Boolean.TRUE;
            addFieldError("percentage", "Percentage is required.");
        }

        // Valido la fecha de inicio.
        if (getSelectedStartDate() == null && getDefaultStartDate() == null) {
            error = Boolean.TRUE;
            addFieldError("startDate", "Start Date is required.");
        }

        // Valido la fecha de fin.
        if (getSelectedEndDate() == null && getDefaultEndDate() == null) {
            error = Boolean.TRUE;
            addFieldError("endDate", "End Date is required.");
        }

        Employee emp;
        if (!StringUtils.isEmpty(getEmployeeId()) && !getEmployeeId().equalsIgnoreCase(getSelectedGanttEmployeeId())
                && !StringUtils.isEmpty(getEmployeeId())) {
            // es un nuevo assignment
            emp = getEmployeeService().searchById(Long.decode(getEmployeeId()));
        } else if (!StringUtils.isEmpty(getSelectedGanttEmployeeIdBefore())) {
            // es un assignment editado
            emp = getEmployeeService().searchById(Long.decode(getSelectedGanttEmployeeIdBefore()));
            setEmployeeId(getSelectedGanttEmployeeIdBefore());
        } else {
            addFieldError("employee", "No employee is selected.");
            setMappedRequest(CONFIRM_NEW);
            return SUCCESS;
        }

        // Valido la fecha de inicio.
        calculateStartAndEndDate(emp, error);

        // Realizo acciones si alguno de los campos no cumple con la
        // validacion.
        if (error) {
            setModel(null);
            setMappedRequest(CREATE_NEW);
            if (getAssignmentIdBefore() == null || getAssignmentIdBefore().equals("")) {
                // Cargo los datos necesarios para volver
                // a la pagina de crear nueva asignacion
                resetAttributesForCreateNewAssignments();
                this.loadEmployeeAssignmentsList();
                return INPUT;
            } else {
                // Cargo los datos necesarios para volver
                // a la pagina de editar una asignacion
                loadSelectedEmployeeAssignment();
                this.loadEmployeeAssignmentsList(getAssignment().getEmployee());

                setGanttStartDate(StaffingActionHelper.GenerarValorInicialDeStartDate());

                setGanttEndDate(StaffingActionHelper.GenerarValorInicialDeEndDate());

                return INPUT;
            }
        }

        setMappedRequest(CONFIRM_NEW);
        return SUCCESS;
    }

    private boolean validateNoDuplicateAssigment(final EmployeeAssignment employeeAssignment, final Project project) {
        employeeAssignment.setProject(project);
        return getEmployeeAssignmentService().checkAssigmentIsCharged(employeeAssignment);
    }

    private void calculateStartAndEndDate(final Employee emp, Boolean error) {
        if (getSelectedStartDate() != null && getSelectedEndDate() != null) {
            if (getSelectedStartDate().compareTo(getSelectedEndDate()) > 0) {
                error = Boolean.TRUE;
                addFieldError("endDate", "Verify the date period entered since it's incorrect.");
            }
            if (getSelectedStartDate().after(emp.getDateStart()) && emp.getDateEnd() != null
                    && getSelectedEndDate().before(emp.getDateEnd())) {
                error = Boolean.TRUE;
                addFieldError("endDate", "The dates entered should belong to the employee's working period.");
            }
        } else {
            if (getDefaultStartDate().compareTo(getDefaultEndDate()) > 0) {
                error = Boolean.TRUE;
                addFieldError("endDate", "Verify the date period entered since it's incorrect.");
            }
            if (getDefaultStartDate().after(emp.getDateStart()) && emp.getDateEnd() != null
                    && getDefaultEndDate().before(emp.getDateEnd())) {
                error = Boolean.TRUE;
                addFieldError("endDate", "The dates entered should belong to the employee's working period.");
            }
        }

    }

    /**
     * Prepara la pantalla para editar la asignacion seleccionada.
     * 
     * @return
     */
    @SkipValidation
    public final String editAssignment() {

        loadSelectedEmployeeAssignment();
        this.loadEmployeeAssignmentsList(getAssignment().getEmployee());
        loadDates();

        setSelectedStartDate(getAssignment().getStartDate().getTime());
        setSelectedEndDate(getAssignment().getEndDate().getTime());

        setSelectedRoleCode(getAssignment().getAssignedRole().getCode());
        setSelectedRoleName(getAssignment().getAssignedRole().getDescription());

        setSelectedAssignmentPercentage(Integer.toString((int) getAssignment().getAssignmentPorcentage()));
        setSelectedProjectId(getAssignment().getProject().getId().toString());
        setSelectedProjectName(getAssignment().getProject().getName());

        setDescription(getAssignment().getComments());
        setAddonAvailable(getAssignment().getAssignmentType().equals(AssignmentType.AddOnAvailable));
        setAddonNotAvailable(getAssignment().getAssignmentType().equals(AssignmentType.AddOnNotAvailable));
        setAssignTentative(getAssignment().getTentative());
        setAssignmentIdBefore(String.valueOf(getAssignmentId()));

        setAssignmentIdBefore(getAssignment().getId().toString());

        setGanttStartDate(StaffingActionHelper.GenerarValorInicialDeStartDate());

        setGanttEndDate(StaffingActionHelper.GenerarValorInicialDeEndDate());

        if (!StringUtils.isBlank(getSelectedGanttEmployeeIdBefore())) {
            setSelectedGanttEmployeeNameBefore(getEmployeeService()
                    .searchById(Long.parseLong(getSelectedGanttEmployeeIdBefore())).getPerson().getName());
        }

        setMappedRequest(EDIT);
        return SUCCESS;
    }

    public final String editAssignmentFromPopUp() {

        loadSelectedEditEmployeeAssignment();
        this.loadEmployeeAssignmentsList(getAssignment().getEmployee());
        loadDates();

        setSelectedGanttEmployeeIdBefore(getAssignment().getEmployee().getId().toString());
        setSelectedGanttEmployeeNameBefore(getAssignment().getEmployee().getPerson().getName());

        setSelectedStartDate(getAssignment().getStartDate().getTime());
        setSelectedEndDate(getAssignment().getEndDate().getTime());

        setSelectedRoleCode(getAssignment().getAssignedRole().getCode());
        setSelectedRoleName(getAssignment().getAssignedRole().getDescription());

        setSelectedAssignmentPercentage(Integer.toString((int) getAssignment().getAssignmentPorcentage()));
        setSelectedProjectId(getAssignment().getProject().getId().toString());
        setSelectedProjectName(getAssignment().getProject().getName());

        setDescription(getAssignment().getComments());
        setAddonAvailable(getAssignment().getAssignmentType().equals(AssignmentType.AddOnAvailable));
        setAddonNotAvailable(getAssignment().getAssignmentType().equals(AssignmentType.AddOnNotAvailable));
        setAssignTentative(getAssignment().getTentative());
        setAssignmentIdBefore(getAssignment().getId().toString());

        setGanttStartDate(StaffingActionHelper.GenerarValorInicialDeStartDate());

        setGanttEndDate(StaffingActionHelper.GenerarValorInicialDeEndDate());

        if (!StringUtils.isBlank(getSelectedGanttEmployeeIdBefore())) {
            setSelectedGanttEmployeeNameBefore(getEmployeeService()
                    .searchById(Long.parseLong(getSelectedGanttEmployeeIdBefore())).getPerson().getName());
        }
        saveSearchCriteria();

        if (isFromPopUp()) {
            getSession().put("return_to_search_action",
                    "RequirementAssignmentRelationshipAction_listUsingFilterAttributesFromSession");
        }

        setMappedRequest(EDIT);
        return SUCCESS;
    }

    /**
     * Carga los campos con los valores por defecto, que son auqellos que
     * corresponden al proximo periodo en el que el empleado no tiene ninguna
     * asignacion.
     * 
     * @return
     */
    private void loadAttributesWithNextNoAssignment(final Employee employee) {

        Calendar dateTo = Calendar.getInstance();
        dateTo.add(Calendar.YEAR, 1);

        List<EmployeeAssignmentDTO> noAssignments = getEmployeeAssignmentService().findAvailableResource(employee,
                Calendar.getInstance().getTime(), dateTo.getTime(), false, true, false, false, true, false, false,
                null, null, false, null);

        if (noAssignments != null && noAssignments.size() != 0) {
            EmployeeAssignmentDTO nextNoAssignment = noAssignments.iterator().next();
            for (EmployeeAssignmentDTO next : noAssignments) {
                if (next.getFrom().compareTo(nextNoAssignment.getFrom()) < 0) {
                    nextNoAssignment = next;
                }
            }

            setSelectedStartDate(nextNoAssignment.getFrom().getTime());
            setSelectedEndDate(nextNoAssignment.getTo().getTime());

            setSelectedAssignmentPercentage(Integer.toString(nextNoAssignment.getPorcentage().intValue()));
        } else {
            setSelectedStartDate(null);
            setSelectedEndDate(null);
        }
    }

    /**
     * Guarda los cambios de la asignacion editada.
     * 
     * @return
     */
    public final String confirmEditedAssignment() {

        loadSelectedEmployeeAssignment();
        this.loadEmployeeAssignmentsList(getAssignment().getEmployee());
        loadDates();

        setGanttStartDate(StaffingActionHelper.GenerarValorInicialDeStartDate());

        setGanttEndDate(StaffingActionHelper.GenerarValorInicialDeEndDate());

        setMappedRequest(EDIT);
        return SUCCESS;
    }

    /**
     * Valida que los datos ingresados para editar una asignacion sean validos.
     * 
     * @return
     */
    public String validateConfirmEditedAssignment() {
        if (getValidated()) {// already validated and accepted the message
            setMappedRequest(EDIT);
            return SUCCESS;
        }

        Boolean error = Boolean.FALSE;

        // Valido que el proyecto indicado realmente exista.
        if (StringUtils.isEmpty(getSelectedProjectId()) || StringUtils.isEmpty(getSelectedProjectName())) {
            error = Boolean.TRUE;
            addFieldError("project", "Seleccione un proyecto valido");
        }

        // Valido que el rol indicado sea valido.
        if (StringUtils.isEmpty(getSelectedRoleCode())) {
            error = Boolean.TRUE;
            addFieldError("role", "Seleccione un rol valido");
        }

        // valido que el porcentaje sea menor o igual a 100 y mayor a cero.
        if (StringUtils.isEmpty(getSelectedAssignmentPercentage())
                || Long.parseLong(getSelectedAssignmentPercentage()) <= 0
                || Long.parseLong(getSelectedAssignmentPercentage()) > 100) {
            error = Boolean.TRUE;
            addFieldError("percentage", "El porcentaje debe ser un numero entre 1 y 100");
        }

        // Valido la fecha de inicio.
        if (getSelectedStartDate() == null) {
            error = Boolean.TRUE;
            addFieldError("startDate", "La fecha de inicio debe respetar el formato dd/mm/aaaa");
        }

        // Valido la fecha de fin.
        if (getSelectedEndDate() == null) {
            error = Boolean.TRUE;
            addFieldError("endDate", "La fecha de fin debe respetar el formato dd/mm/aaaa");
        }

        // Valido la fecha de inicio.
        if (getSelectedStartDate() != null && getSelectedEndDate() != null
                && getSelectedStartDate().compareTo(getSelectedEndDate()) > 0) {
            error = Boolean.TRUE;
            addFieldError("endDate", "La fecha de fin debe ser superior a la fecha de inicio");
        }

        if (error) {
            setModel(null);
            setMappedRequest(EDIT);
            return editAssignment();
        }

        setMappedRequest(EDIT);
        return SUCCESS;
    }

    /**
     * Elimina la asignacion seleccionada.
     * 
     * @return
     */
    @SkipValidation
    public final String deleteAssignment() {
        EmployeeAssignment assignment = getEmployeeAssignmentService().searchById(
                Long.parseLong(getAssignmentToDelete()));
        getEmployeeAssignmentService().delete(assignment);

        setSelectedRoleCode(getSelectedRoleCode());
        setSelectedRoleName(getSelectedRoleName());
        setSelectedGanttEmployeeId(getEmployeeId());
        setEmployeeId(getEmployeeId());

        setResetAttributes("true");
        setMappedRequest(DELETE);
        return SUCCESS;
    }

    /**
     * Carga la lista de asignaciones del empleado.
     */
    private void loadEmployeeAssignmentsList(final Employee employee) {
        // Cargo la lista para mostrar el gantt de asignaciones.
        setEmployeeAssignmentList(getEmployeeAssignmentService().findAvailableResource(employee,
                StaffingActionHelper.GenerarValorInicialDeStartDate(),
                StaffingActionHelper.GenerarValorInicialDeEndDate(), true, false, true, true, true, true, true, null,
                null, false, null));

        // Cargo la lista que se muestra en la tabla de asignaciones.
        List<EmployeeAssignment> allEmployeeAssignments = EmployeeAssignmentHelper.findAssignmentsForEmployee(employee,
                getEmployeeAssignmentService().findAllIncludingNoAssignableToProjectEmployees());
        Collections.sort(allEmployeeAssignments, new Comparator<EmployeeAssignment>() {

            @Override
            public int compare(final EmployeeAssignment o1, final EmployeeAssignment o2) {
                return o2.getStartDate().compareTo(o1.getStartDate());
            }
        });
        setAssignmentList(allEmployeeAssignments);
    }

    /**
     * Carga la lista de asignaciones del empleado, apartir del id del empleado.
     */
    private void loadEmployeeAssignmentsList() {
        Employee employee;
        if (StringUtils.isNotEmpty(getEmployeeId())) {
            employee = getEmployeeService().searchById(Long.decode(getEmployeeId()));
            this.loadEmployeeAssignmentsList(employee);
        }
    }

    /**
     * Carga la asignacion seleccionada.
     */
    private void loadSelectedEmployeeAssignment() {
        EmployeeAssignment assignment;
        if (getAssignmentId() != 0) {
            assignment = getEmployeeAssignmentService().searchById(getAssignmentId());
        } else {
            assignment = getEmployeeAssignmentService().searchById(Long.parseLong(getAssignmentIdBefore()));
        }
        setAssignment(assignment);
    }

    private void loadSelectedEditEmployeeAssignment() {
        EmployeeAssignment assignment = null;
        if (getSelectedAssignmentId() != 0) {
            assignment = getEmployeeAssignmentService().searchById(Long.valueOf(getSelectedAssignmentId()));
        }

        setAssignment(assignment);
    }

    private void saveSearchCriteria() {
        AssignmentFilters filters = new AssignmentFilters();
        filters.setActualPage(getActualPage());
        filters.setGanttEndDate(getGanttEndDate());
        filters.setGanttStartDate(getGanttStartDate());
        filters.setSelectedEmployeeId(getSelectedEmployeeId());
        filters.setSelectedEmployeeName(getSelectedEmployeeName());
        filters.setSelectedProjectIdFilter(getSelectedProjectIdFilter());
        filters.setSelectedProjectNameFilter(getSelectedProjectNameFilter());
        filters.setSelectedProjectId(getSelectedProjectId());
        filters.setSelectedProjectName(getSelectedProjectName());
        filters.setSelectedRoles(getSelectedRoles());
        filters.setSelectedRolesBefore(getSelectedRolesBefore());
        filters.setShowAddOnAvailable(isShowAddOnAvailable());
        filters.setShowAddOnNotAvailable(isShowAddOnNotAvailable());
        filters.setShowAsignadoCliente(getShowAsignadoCliente());
        filters.setShowInterno(getShowInterno());
        filters.setShowNoAsignado(getShowNoAsignado());
        filters.setShowTentativesAvailableResources(getShowTentativesAvailableResources());
        filters.setShowTodos(getShowTodos());
        filters.setElegibleProjectMember(isOnlyElegibleProjectMember());

        getSession().put("assignmentFilters", filters);
        getSession().put("return_to_search_action", "EmployeeAssignmentAction_listUsingFilterAttributesFromSession");
    }

    public String listUsingFilterAttributesFromSession() {

        if (getSession().containsKey("assignmentFilters")) {
            AssignmentFilters filters = (AssignmentFilters) getSession().get("assignmentFilters");

            setActualPage(filters.getActualPage());
            setSelectedEndDate(filters.getGanttEndDate());
            setSelectedStartDate(filters.getGanttStartDate());
            setSelectedEmployeeId(filters.getSelectedEmployeeId());
            setSelectedEmployeeName(filters.getSelectedEmployeeName());
            setSelectedProjectIdFilter(filters.getSelectedProjectIdFilter());
            setSelectedProjectNameFilter(filters.getSelectedProjectNameFilter());
            setSelectedProjectId(filters.getSelectedProjectId());
            setSelectedProjectName(filters.getSelectedProjectName());
            setSelectedRoles(filters.getSelectedRoles());
            setSelectedRolesBefore(filters.getSelectedRolesBefore());
            setShowAddOnAvailable(filters.isShowAddOnAvailable());
            setShowAddOnNotAvailable(filters.isShowAddOnNotAvailable());
            setShowAsignadoCliente(filters.getShowAsignadoCliente());
            setShowInterno(filters.getShowInterno());
            setShowNoAsignado(filters.getShowNoAsignado());
            setShowTentativesAvailableResources(filters.getShowTentativesAvailableResources());
            setShowTodos(filters.getShowTodos());
            setOnlyElegibleProjectMember(filters.getElegibleProjectMember());

            getSession().remove("assignmentFilters");
        }

        return listAssignments();
    }

    public List<Project> getProjectsList() {
        return getProjectService().findAll();
    }

    public List<JobFunction> getRoles() {
        return RecruitServiceLocator.getJobProvider().findAllJobFunctions();
    }

    public List<Employee> getEmployeeList() {
        return (List<Employee>) getEmployeeService().getAllCurrentEmployees();
    }

    public String getStartDateAsString() {
        if (getGanttStartDate() != null)
            return DateUtil.getFechaFormateada(getGanttStartDate());
        else
            return DateUtil.getFechaFormateada(StaffingActionHelper.GenerarValorInicialDeStartDate());
    }

    public String getEndDateAsString() {
        if (getGanttEndDate() != null)
            return DateUtil.getFechaFormateada(getGanttEndDate());
        else
            return DateUtil.getFechaFormateada(StaffingActionHelper.GenerarValorInicialDeEndDate());
    }

    @Override
    protected CrudService<EmployeeAssignment> getCrudService() {
        return getEmployeeAssignmentService();
    }

    @Override
    public void setSession(final Map<String, Object> session) {
        this.session = session;
    }

    public Map getSession() {
        return session;
    }

    public void setEmployeeAssignmentService(final EmployeeAssignmentService employeeAssignmentService) {
        this.employeeAssignmentService = employeeAssignmentService;
    }

    public EmployeeAssignmentService getEmployeeAssignmentService() {
        return employeeAssignmentService;
    }

    public void setEmployeeAssignmentList(final List<EmployeeAssignmentDTO> employeeAssignmentList) {
        this.employeeAssignmentList = employeeAssignmentList;
    }

    public List<EmployeeAssignmentDTO> getEmployeeAssignmentList() {
        return employeeAssignmentList;
    }
    
    public List<Location> getLocationList() {
    	List<Location> locations = CoreServiceLocator.getLocationService().findTopLevelLocations(getAuthPerson().getDomain());
    	List<Location> addedLocations = new ArrayList<Location>();
    	Iterator<Location> iterator = locations.iterator();
    	while (iterator.hasNext()) {
    		Location location = iterator.next();
			Iterator<Location> children = location.getChildren().iterator();
			while (children.hasNext()) {
				Location citys = children.next();
				addedLocations.add(citys);
				Iterator<Location> cityIter = citys.getChildren().iterator();
				while (cityIter.hasNext()){
					addedLocations.add(cityIter.next());
				}
			}
    	}
    	locations.addAll(addedLocations);
    	
    	Collections.sort(locations, new Comparator<Object>(){

			@Override
			public int compare(Object o1, Object o2) {
				return ((Location)o1).getName().compareToIgnoreCase(((Location)o2).getName());
			}
		});
		return locations;
	}

	public void setLocationList(List<Location> locationlist) {
		this.locationList = locationlist;
	}

	public void setEmployeeId(final String employeeId) {
        this.employeeId = employeeId;
    }

    public String getEmployeeId() {
        return employeeId;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(final String projectId) {
        this.projectId = projectId;
    }

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(final String roleId) {
        this.roleId = roleId;
    }

    public void setEmployeeService(final EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    public void setAssignmentId(final long assignmentId) {
        this.assignmentId = assignmentId;
    }

    public long getAssignmentId() {
        return assignmentId;
    }

    public void setAssignment(final EmployeeAssignment assignment) {
        this.assignment = assignment;
    }

    public EmployeeAssignment getAssignment() {
        return assignment;
    }

    public void setSelectedProjectId(final String selectedProjectId) {
        this.selectedProjectId = selectedProjectId;
    }

    public String getSelectedProjectId() {
        return selectedProjectId;
    }

    public void setSelectedProjectName(final String selectedProjectName) {
        this.selectedProjectName = selectedProjectName;
    }

    public String getSelectedProjectName() {
        return selectedProjectName;
    }

    public void setProjectService(final ProjectService projectService) {
        this.projectService = projectService;
    }

    public ProjectService getProjectService() {
        return projectService;
    }

    public void setSelectedRoleCode(final String selectedRoleCode) {
        this.selectedRoleCode = selectedRoleCode;
    }

    public String getSelectedRoleCode() {
        String toReturn = "";
        if (selectedRoleCode != null) {
            if (!selectedRoleCode.equalsIgnoreCase("")) {
                toReturn = selectedRoleCode.substring(selectedRoleCode.lastIndexOf(" ") + 1);
                if (toReturn.equalsIgnoreCase("")) {
                    toReturn = selectedRoleCode.substring(0, selectedRoleCode.lastIndexOf(","));
                }
                return toReturn;
            }
        }
        return selectedRoleCode;
    }

    public void setSelectedRoleName(final String selectedRoleName) {
        this.selectedRoleName = selectedRoleName;
    }

    public String getSelectedRoleName() {
        return selectedRoleName;
    }

    public void setSelectedStartDate(final Date selectedStartDate) {
        this.selectedStartDate = selectedStartDate;
    }

    public Date getSelectedStartDate() {
        if (selectedStartDate != null)
            return selectedStartDate;
        return StaffingActionHelper.GenerarValorInicialDeStartDate();
    }

    public void setSelectedEndDate(final Date selectedEndDate) {
        this.selectedEndDate = selectedEndDate;
    }

    public Date getSelectedEndDate() {
        if (selectedEndDate != null)
            return selectedEndDate;
        return StaffingActionHelper.GenerarValorInicialDeEndDate();
    }
    
	public String getSelectedLocationId() {
		return selectedLocationId;
	}

	public void setSelectedLocationId(String selectedLocationId) {
		this.selectedLocationId = selectedLocationId;
	}

	public String getSelectedLocationName() {
		return selectedLocationName;
	}

	public void setSelectedLocationName(String selectedLocationName) {
		this.selectedLocationName = selectedLocationName;
	}

	public Date getDefaultStartDate() {
        return new GregorianCalendar().getTime();
    }

    public void setDefaultStartDate(final Date defaultStartDate) {
        this.defaultStartDate = defaultStartDate;
    }

    public Date getDefaultEndDate() {
        Calendar endDate = new GregorianCalendar();
        endDate.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR) + 1);
        return endDate.getTime();
    }

    public void setDefaultEndDate(final Date defaultEndDate) {
        this.defaultEndDate = defaultEndDate;
    }

    public void setDescription(final String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    public void setSelectedAssignmentPercentage(final String selectedAssignmentPercentage) {
        this.selectedAssignmentPercentage = selectedAssignmentPercentage;
    }

    public String getSelectedAssignmentPercentage() {
        return selectedAssignmentPercentage;
    }

    public void setActualPage(final String actualPage) {
        this.actualPage = actualPage;
    }

    public String getActualPage() {
        return actualPage;
    }

    public void setSelectedGanttEmployeeId(final String selectedGanttEmployeeId) {
        this.selectedGanttEmployeeId = selectedGanttEmployeeId;
    }

    public String getSelectedGanttEmployeeId() {
        return selectedGanttEmployeeId;
    }

    public void setShowTentativesAvailableResources(final boolean showTentativesAvailableResources) {
        this.showTentativesAvailableResources = showTentativesAvailableResources;
    }

    public boolean getShowTentativesAvailableResources() {
        return showTentativesAvailableResources;
    }

    public void setSelectedRoles(final String[] selectedRoles) {
        this.selectedRoles = selectedRoles;
    }

    public String[] getSelectedRoles() {
        return selectedRoles;
    }

    public String getSelectedProjectIdFilter() {
        return selectedProjectIdFilter;
    }

    public void setSelectedProjectIdFilter(final String selectedProjectIdFilter) {
        this.selectedProjectIdFilter = selectedProjectIdFilter;
    }

    public String getSelectedProjectNameFilter() {
        return selectedProjectNameFilter;
    }

    public void setSelectedProjectNameFilter(final String selectedProjectNameFilter) {
        this.selectedProjectNameFilter = selectedProjectNameFilter;
    }

    public boolean getShowNoAsignado() {
        return showNoAsignado;
    }

    public void setShowNoAsignado(final boolean showNoAsignado) {
        this.showNoAsignado = showNoAsignado;
    }

    public boolean getShowAsignadoCliente() {
        return showAsignadoCliente;
    }

    public void setShowAsignadoCliente(final boolean showAsignadoCliente) {
        this.showAsignadoCliente = showAsignadoCliente;
    }

    public boolean getShowInterno() {
        return showInterno;
    }

    public void setShowInterno(final boolean showInterno) {
        this.showInterno = showInterno;
    }

    public boolean getShowTodos() {
        return showTodos;
    }

    public void setShowTodos(final boolean showTodos) {
        this.showTodos = showTodos;
    }

    public String getNoAsignadoColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.NoAsignado);
    }

    public String getTimeOffColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.TimeOff);
    }

    public String getAsignadoClienteColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.AsignadoCliente);
    }

    public String getAddOnAvailableColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.AddOnAvailable);
    }

    public String getAddOnNotAvailableColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.AddOnNotAvailable);
    }

    public String getInternoColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.Interno);
    }

    public String getAssignmentIdBefore() {
        return assignmentIdBefore;
    }

    public void setAssignmentIdBefore(final String assignmentIdBefore) {
        this.assignmentIdBefore = assignmentIdBefore;
    }

    public String getAssignmentToDelete() {
        return assignmentToDelete;
    }

    public void setAssignmentToDelete(final String assignmentToDelete) {
        this.assignmentToDelete = assignmentToDelete;
    }

    public void setAssignmentList(final List<EmployeeAssignment> assignmentList) {
        this.assignmentList = assignmentList;
    }

    public List<EmployeeAssignment> getAssignmentList() {
        return assignmentList;
    }

    public void setSelectedEmployeeId(final String selectedEmployeeId) {
        this.selectedEmployeeId = selectedEmployeeId;
    }

    public String getSelectedEmployeeId() {
        return selectedEmployeeId;
    }

    public void setSelectedEmployeeName(final String selectedEmployeeName) {
        this.selectedEmployeeName = selectedEmployeeName;
    }

    public String getSelectedEmployeeName() {
        return selectedEmployeeName;
    }

    public void setGanttStartDate(final Date ganttStartDate) {
        this.ganttStartDate = ganttStartDate;
    }

    public Date getGanttStartDate() {
        return ganttStartDate;
    }

    public void setGanttEndDate(final Date ganttEndDate) {
        this.ganttEndDate = ganttEndDate;
    }

    public Date getGanttEndDate() {
        return ganttEndDate;
    }

    public void setSelectedRolesBefore(final Collection<String> selectedRolesBefore) {
        this.selectedRolesBefore = selectedRolesBefore;
    }

    public Collection<String> getSelectedRolesBefore() {
        return selectedRolesBefore;
    }

    public String getResetAttributes() {
        return resetAttributes;
    }

    public void setResetAttributes(final String resetAttributes) {
        this.resetAttributes = resetAttributes;
    }

    public void setValidated(final Boolean validated) {
        this.validated = validated;
    }

    public Boolean getValidated() {
        return validated;
    }

    private void resetAttributesForm() {
        setShowTentativesAvailableResources(true);
        setShowNoAsignado(false);
        setShowAsignadoCliente(true);
        setShowAddOnAvailable(true);
        setShowAddOnNotAvailable(false);
        setShowInterno(true);
        setShowTimeOff(false);

        setSelectedStartDate(StaffingActionHelper.GenerarValorInicialDeStartDate());
        setSelectedEndDate(StaffingActionHelper.GenerarValorInicialDeEndDate());

        setSelectedEmployeeId("");
        setSelectedEmployeeName("");

        setSelectedProjectIdFilter("");
        setSelectedProjectNameFilter("");

        selectedRolesBefore.clear();
        setSelectedRoles(new String[] {});

        setResetAttributes("false");
    }

    public String getSelectedGanttEmployeeIdBefore() {
        return selectedGanttEmployeeIdBefore;
    }

    public void setSelectedGanttEmployeeIdBefore(final String selectedGanttEmployeeIdBefore) {
        this.selectedGanttEmployeeIdBefore = selectedGanttEmployeeIdBefore;
    }

    public String getSelectedGanttEmployeeNameBefore() {
        return selectedGanttEmployeeNameBefore;
    }

    public void setSelectedGanttEmployeeNameBefore(final String selectedGanttEmployeeNameBefore) {
        this.selectedGanttEmployeeNameBefore = selectedGanttEmployeeNameBefore;
    }

    public String getReturnToSearchAction() {
        return (String) getSession().get("return_to_search_action");
    }

    public boolean getShowTimeOff() {
        return showTimeOff;
    }

    public void setShowTimeOff(final boolean showTimeOff) {
        this.showTimeOff = showTimeOff;
    }

    /**
     * @param assignTentative
     *            the assignTentative to set
     */
    public void setAssignTentative(final boolean assignTentative) {
        this.assignTentative = assignTentative;
    }

    /**
     * @return the assignTentative
     */
    public boolean isAssignTentative() {
        return assignTentative;
    }

    /**
     * @param showAddOnAvailable
     *            the showAddOnAvailable to set
     */
    public void setShowAddOnAvailable(final boolean showAddOnAvailable) {
        this.showAddOnAvailable = showAddOnAvailable;
    }

    /**
     * @return the showAddOnAvailable
     */
    public boolean isShowAddOnAvailable() {
        return showAddOnAvailable;
    }

    /**
     * @param showAddOnNotAvailable
     *            the showAddOnNotAvailable to set
     */
    public void setShowAddOnNotAvailable(final boolean showAddOnNotAvailable) {
        this.showAddOnNotAvailable = showAddOnNotAvailable;
    }

    /**
     * @return the showAddOnNotAvailable
     */
    public boolean isShowAddOnNotAvailable() {
        return showAddOnNotAvailable;
    }

    /**
     * @param addonNotAvailable
     *            the addonNotAvailable to set
     */
    public void setAddonNotAvailable(final boolean addonNotAvailable) {
        this.addonNotAvailable = addonNotAvailable;
    }

    /**
     * @return the addonNotAvailable
     */
    public boolean isAddonNotAvailable() {
        return addonNotAvailable;
    }

    /**
     * @param addonAvailable
     *            the addonAvailable to set
     */
    public void setAddonAvailable(final boolean addonAvailable) {
        this.addonAvailable = addonAvailable;
    }

    /**
     * @return the addonAvailable
     */
    public boolean isAddonAvailable() {
        return addonAvailable;
    }

    public void setOnlyElegibleProjectMember(final boolean elegibleProjectMember) {
        onlyElegibleProjectMember = elegibleProjectMember;
    }

    public boolean isOnlyElegibleProjectMember() {
        return onlyElegibleProjectMember;
    }

    /**
     * @return the createRequirement
     */
    public boolean isCreateRequirement() {
        return createRequirement;
    }

    /**
     * @param createRequirement
     *            the createRequirement to set
     */
    public void setCreateRequirement(final boolean createRequirement) {
        this.createRequirement = createRequirement;
    }

    /**
     * @return the fromPopUp
     */
    public boolean isFromPopUp() {
        return fromPopUp;
    }

    /**
     * @param fromPopUp
     *            the fromPopUp to set
     */
    public void setFromPopUp(final boolean fromPopUp) {
        this.fromPopUp = fromPopUp;
    }

    public EditedAssignment getEditedAssignment() {
        return editedAssignment;
    }

    public void setEditedAssignment(final EditedAssignment editedAssignment) {
        this.editedAssignment = editedAssignment;
    }

    public Long getSelectedAssignmentId() {
        return selectedAssignmentId;
    }

    public void setSelectedAssignmentId(final Long selectedAssignmentId) {
        this.selectedAssignmentId = selectedAssignmentId;
    }

}
